package com.baixun.gasadmin.controller;

import com.baixun.gasentity.dto.VideoSummaryDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baixun.gassystem.service.SysLawEnforcementVideoService;
import com.baixun.gascommon.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Api(tags = "执法仪列表")
@RestController
@RequestMapping("/sys/law-enforcement-video")

//TODO 数据不全，待确认
public class SysLawEnforcementVideoController {

    @Autowired
    private SysLawEnforcementVideoService sysLawEnforcementVideoService;

    /**
     * 分页查询每天的视频汇总（数量、大小）
     *
     * @param page 页码
     * @param size 每页数量
     * @return 分页后的视频汇总数据
     */
    @ApiOperation(value = "分页查询每天的视频汇总", notes = "按天汇总执法仪视频的数量和大小")
    @GetMapping("/summary")
    public R<IPage<VideoSummaryDTO>> getDailyVideoSummary(

            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "size",defaultValue = "4") Integer size) {

        // 将变量类型改为 IPage<VideoSummaryDTO>
        IPage<VideoSummaryDTO> summaryPage = sysLawEnforcementVideoService.selectDailyVideoSummary(page, size);
        return R.success(summaryPage);
    }


    @ApiOperation(value = "根据日期查询视频记录", notes = "查询指定日期的所有视频记录")
    @GetMapping("/records")
    public R getVideoRecordsByDate(
            @ApiParam(value = "日期（格式：yyyy-MM-dd）", required = false)
            @RequestParam(value = "date", required = false) String date) {

        // 如果没有传递日期，默认使用当前日期
        if (date == null || date.isEmpty()) {
            date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }

        // 设置默认的分页参数 page=1, size=10
        Integer page = 1; // 默认第一页
        Integer size = 4; // 默认每页10条数据

        // 调用service层进行分页查询
        IPage<VideoSummaryDTO> summaryPage = sysLawEnforcementVideoService.selectDailyVideoSummary(page, size);

        return R.ok(summaryPage);
    }

}